<template lang="jade">
.app-container
  //- .header
    h1.page-title 读者荐购
    a.backup.icon-angle-left(href='javascript:history.go(-1)')
  div
    form.weui-cells
      .weui-cell
        .weui-cell__bd
          input.weui-input(type='text', placeholder='书目名称', v-model='title')
      .weui-cell
        .weui-cell__bd
          input.weui-input(type='text', placeholder='出版社', v-model='publisher')
      .weui-cell
        .weui-cell__bd
          input.weui-input(type='text', placeholder='ISBN编号', v-model='isbn')
      .weui-cell
        .weui-cell__bd
          textarea.weui-input(placeholder='推荐理由', v-model='reason')
    .weui-btn-area
      button.btn-blue.weui-btn.weui-btn_primary(@click.stop.prevent='submit') 确定
</template>

<script>
import API from '../api-new'
export default {
  data () {
    return {
      title: null,
      publisher: null,
      isbn: null,
      processing: false
    }
  },
  methods: {
    async submit (e) {
      this.processing = true
      try {
        const data = {
          title: this.title,
          field_publisher: this.publisher,
          field_isbn: this.isbn
        }
        await API.jiangou(data)
        this.title = ''
        this.field_publisher = ''
        this.field_isbn = ''
        this.message = '提交成功'
        this.error = false
      } catch (err) {
        this.message = err.message
        this.error = true
      }
      this.processing = false
    }
  }
}
</script>
